<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	Tekuna :: load('org.tekuna.core.mvc.TekunaView');


	/**
	 * Abstract base implementation of the TekunaView interface. The
	 * core functions, except the process() method, are implemented to
	 * provide a good base for the actual templating mechanism.
	 */

	abstract class AbstractView implements TekunaView {

		protected
			$sBaseDir = '',
			$sTemplate = '',
			$arrValues = array();


		/**
		 * Build a new instance of a TekunaView implementation. Base
		 * directory and template file are given separately to be
		 * altered independently.
		 *
		 * @param string $sBaseDir the base directory of the template
		 * @param string $sTemplate the template file
		 *        (file name and format differ from TekunaView implementation to another)
		 */

	    public function __construct($sBaseDir = '', $sTemplate = '') {

	    	$this -> setTemplateBaseDir($sBaseDir);
	    	$this -> setTemplate($sTemplate);
	    }


		/**
		 * Assign a new placeholder variable with some content
		 *
		 * @param string $sKey the name of the placeholder
		 * @param mixed $mValue the value for the placeholder
		 */

	    public function assign($sVar, $mValue) {

	    	$this -> arrValues[$sVar] = $mValue;
	    }


		/**
		 * Returns the assigned value for the given key. If there
		 * was no value assigned, NULL is returned
		 *
		 * @param string $sVar the assignment key
		 * @return mixed the value or NULL if not assigned
		 */

	    public function getAssignedValue($sVar) {

	    	if (isset($this -> arrValues[$sVar])) {

	    		return $this -> arrValues[$sVar];
	    	}

	    	return NULL;
	    }


		/**
		 * @return array returns an associative array of all assigned values.
		 */

	    public function getAllValues() {

	    	return $this -> arrValues;
	    }


		/**
		 * Set the template's file name
		 *
		 * @param string $sTemplate the new template file name
		 */

	    public function setTemplate($sTemplate) {

	    	$this -> sTemplate = $sTemplate;
	    }


		/**
		 * @return string returns the template file name
		 */

	    public function getTemplate() {

	    	return $this -> sTemplate;
	    }


		/**
		 * Set the template base directory
		 *
		 * @param string $sBaseDir the new base directory for the template
		 */

	    public function setTemplateBaseDir($sBaseDir) {

	    	$this -> sBaseDir = $sBaseDir;
	    }


		/**
		 * @return string returns the template base directory
		 */

	    public function getTemplateBaseDir() {

	    	return $this -> sBaseDir;
	    }
	}

